package linc.cool.listen;

import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @author yqlin
 * @date 2022/3/4 3:32 上午
 * @description
 */
@Slf4j
@Component
public class QpsListener implements ChannelAwareMessageListener {
    @Override
    public void onMessage(Message message, Channel channel) throws Exception {
        // 获取消息
        log.info(new String(message.getBody()));
        // 处理业务逻辑
        TimeUnit.SECONDS.sleep(1);
        // 进行消息的签收
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
    }
}
